package window.panel;

import manage.UsernameController;
import window.dialog.RegisterDialog;
import window.service.mouseService;
import window.dialog.LoginDialog;

import javax.swing.*;
import java.awt.*;

public class TopPanel extends JPanel {
    public TopPanel() {
        mouseService mouse = new mouseService();


        this.setLayout(new BorderLayout());
        JPanel selectPanel = new JPanel();
        selectPanel.setLayout(new FlowLayout());
        this.setLayout(new BorderLayout());

        ImageIcon icon = new ImageIcon("res/icon/person_crop_circle_fill_1.png");
        icon.setImage(icon.getImage().getScaledInstance(35, 35, Image.SCALE_SMOOTH));
        JLabel userLabel = new JLabel(icon);

        JLabel name = new JLabel(UsernameController.getUsername());
        name.setFont(new Font("MV Boli", Font.BOLD, 20));

        JButton loginButton = new JButton("Login");
        mouse.ButtonChangeHand(loginButton);
        loginButton.addActionListener(e -> {
            LoginDialog loginDialog = new LoginDialog(name);
        });
        loginButton.setPreferredSize(new Dimension(85, 30));

        JButton registerButton = new JButton("Register");
        mouse.ButtonChangeHand(registerButton);
        registerButton.addActionListener(e -> {
            RegisterDialog registerDialog = new RegisterDialog(name);
        });
        registerButton.setPreferredSize(new Dimension(85, 30));

        selectPanel.add(userLabel);
        selectPanel.add(name);
        this.add(selectPanel, BorderLayout.WEST);

        JPanel loginAndRegisterPanel = new JPanel();
        loginAndRegisterPanel.add(loginButton);
        loginAndRegisterPanel.add(registerButton);
        this.add(loginAndRegisterPanel, BorderLayout.EAST);

        JLabel titleLabel = new JLabel("Let's Go!");
        titleLabel.setFont(new Font("Arial Black", Font.BOLD, 45));
        titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
        this.add(titleLabel, BorderLayout.SOUTH);
    }
}


